<template>
    <view class="cart-item-specs">
        <view class="item-main">
            <view class="specs" v-if="spaceItem.V_AttributeNameValue"><text>规格:</text><text class="specs-text">{{
                spaceItem.V_AttributeNameValue }}</text></view>
            <view class="price" v-if="spaceItem.IsCustomized"><text class="price-text">￥{{ spaceItem.BasePrice
            }}</text><text>/{{ spaceItem.DefaultUnit }}</text><text class="price-text">{{ spaceItem.Ratio }}{{
                        spaceItem.DefaultUnit }}</text><text>/{{ spaceItem.UnitName }}</text><text v-if="spaceItem.IsGift"
                    class="gift">【赠品】</text></view>
            <view class="price" v-else><text class="price-text">￥{{ spaceItem.V_FactPrice }}</text><text>/{{
                spaceItem.UnitName }}</text><text v-if="spaceItem.IsGift" class="gift">【赠品】</text></view>
        </view>
        <view class="item-right">
            <uni-icons class="item-del" type="trash" v-if="selectType == 4" @click="del(spaceItem)"></uni-icons>
            <vk-data-input-number-box v-else class="input-number-box" v-model="spaceItem.Amount" :min="minBuyNum || 0"
                :step="stepBuyNum || 1" :max="getMaxNum(spaceItem)" :step-strictly="stepStrictly"
                :positive-integer="true" @minus="changeAmount(-1, spaceItem)" @blur="changeAmount(0, spaceItem)"
                @plus="changeAmount(1, spaceItem)"></vk-data-input-number-box>
        </view>
    </view>
</template>

<script>
import { upValetCartFn } from "@/utils/valetCartUtil.js"
import utilsOld from "@/utils/utilsOld.js"
import { getProductDisplayForCache } from "@/utils/appInit.js"
export default {
    props: {
        spaceItem: {
            type: Object,
            default: {},
        },
        valetUserId: {
            type: Number,
            default: 0,
        },
        warehouseId: {
            type: Number,
            default: 0,
        },
        selectType: {
            type: [String, Number],
            default: ""
        }
    },
    data() {
        return {
            selectNum: 0,
            stepStrictly: true,
            minBuyNum: 0,
            stepBuyNum: 1,
            maxNum: 99999999,
        }
    },
    mounted() {
        this.stepBuyNum = this.spaceItem.Ratio == 1 ? this.spaceItem.AddNum : 1
    },
    methods: {
        del(item) {
            item.Amount = 0
            this.changeAmount(0, item)
        },
        changeAmount(type, item) {
            item.ValetUserId = this.valetUserId
            item.warehouseId = this.warehouseId
            item.isGift = item.IsGift ? 1 : 0
            console.log(item)
            upValetCartFn(item).then((res) => {
                // this.$forceUpdate()
            })
        },
        getMaxNum(item) {
            if (getProductDisplayForCache().NoCheckStock) {
                return this.maxNum
            } else {
                return item.Stock || this.maxNum
            }
        },
    },
}
</script>

<style lang="scss">
.cart-item-specs {
    display: flex;
    flex-direction: row;
    // border-bottom: solid 1rpx $uni-bg-color-grey;
    padding: $app-page-padding 0;

    .item-left {
        display: flex;
        align-items: center;
        margin-right: 20rpx;
    }

    .item-main {
        display: flex;
        flex: 1;
        flex-direction: column;
        margin-right: 20rpx;

        .specs {}
    }

    .item-right {
        display: flex;
        flex-direction: column;
        justify-content: flex-end;
        align-items: flex-end;

        .item-del {
            margin-bottom: 6rpx;
        }
    }

    .price-text {
        color: $color-red;
        font-size: $font-size-30;
    }
}

.gift {
    color: $app-color-main;
}
</style>
